package com.abel.encrypt.controller;

import cn.shuibo.annotation.Decrypt;
import cn.shuibo.annotation.Encrypt;
import com.abel.encrypt.entity.User;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试控制层
 *
 * @author heyangyang
 * @since 2024-04-25
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Encrypt
    @RequestMapping("/encryption")
    public User test() {
        User user = new User();
        user.setName("张三");
        user.setAge(111);
        return user;
    }

    @Decrypt
    @PostMapping("/decryption")
    public String decryption(@RequestBody User user) {
        log.info("user: {}", JSON.toJSONString(user));
        return JSON.toJSONString(user);
    }

}
